﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Hospital_search_company_psnext : System.Web.UI.Page
{
    //int HCPSProjectID;  2007/08/22 马
    public string  HCSAccountId_PS, SupplyGoodsId;
    

    string strArea = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        //HCPSProjectID = SysFun.ToInt(Request.QueryString["ProjectId"].ToString());   2007/08/22 马
        //HCPSRowNum = SysFun.ToLong(Request.QueryString["rownum"]);

        //HCSAccountId_PS = 0;
        //HCPHosId = SysFun.ToLong(Request.QueryString["hspid"]);


        //string dd = "select Accountid_ps1,SupplyGoodsId from PurchaseTable where hspid=" + HCPHosId;
        //Db db = new Db();
        //DataTable dt = db.DataTable(dd);
        //db.Close();
        //if (dt.Rows.Count > 0)
        //{
        //    if ((dt.Rows[0][0] != null) && (dt.Rows[0][0].ToString() != ""))
        //    {
        //        HCSAccountId_PS = SysFun.ToLong(dt.Rows[0][0]);
        //    }
        //    else
        //    {
        //        HCSAccountId_PS = 0;
        //    }
        //    if ((dt.Rows[0][1] != null) && (dt.Rows[0][1].ToString() != ""))
        //    {
        //        SupplyGoodsId = SysFun.ToLong(dt.Rows[0][1]);
        //    }
        //    else
        //    {
        //        HCSAccountId_PS = 0;
        //    }
        //}
        //dt.Clear();

        //if (Request.Form["txtAreaId"] != "")
        //{
        //    strArea = Request.Form["txtAreaId"].ToString();
        //}
        HCSAccountId_PS = SysFun.IsSQL(Request.QueryString["Accountid_PS"].ToString());
        SupplyGoodsId = SysFun.IsSQL(Request.QueryString["SupplyGoodsId"].ToString());
        
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            strArea = _Account.AreaId;
            showGridView();
        }

    }
    /// <summary>
    /// 数据绑定
    /// </summary>
    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "SupplyPlan_GoodsNext,SupplyPlan_Goods";//要查询的表明
        dbPage.Key = "id";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "Accountid_ps_B1,companyname_ps_B1,areaid,areaname";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 30;                                                    //没有显示记录条数   
        dbPage.OrderBy = "areaid";                  //排序字段
        dbPage.OrderByIsDesc = true;
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlAttorney.DataSource = dr;
        DlAttorney.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", CompanyName = "";

        strtemp = " SupplyPlan_GoodsNext.SupplyGoodsId =SupplyPlan_Goods.SupplyGoodsId and isuse=1 and  SupplyPlan_GoodsNext.SupplyGoodsId='" + SupplyGoodsId.ToString() + "' and Accountid_ps_M ='" + HCSAccountId_PS.ToString() + "' and SupplyPlan_GoodsNext.PS_ChangeStatus=1 and";

       
        if (strArea != "")
        {
            strtemp += " areaid= " + strArea + " and";
        }

        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }

  
}
